package MenuTest;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

public  class  myNotePad{
    private static void Pad(){

        JFrame frame = new JFrame("NotePad");
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500,450);
        frame.setLocation(300,200);

        JMenuBar menuBar = new JMenuBar();
        JMenu menu1 = new JMenu("新建");
        JMenu menu2 = new JMenu("编辑");
        JMenu menu3 = new JMenu("资源");
        JMenu menu4 = new JMenu("帮助");
        menuBar.add(menu1);
        menuBar.add(menu2);

        JMenuItem menuItem1 = new JMenuItem("文件");
        JMenuItem menuItem2 = new JMenuItem("打开");
        JMenuItem menuItem3 = new JMenuItem("设置");
        JMenuItem menuItem4 = new JMenuItem("聊天");
        menu1.add(menuItem1);
        menu1.addSeparator();
        menu1.add(menuItem2);
        menu1.add(menuItem3);
        menu1.add(menuItem4);


        menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));
        menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK));

        menuItem1.addActionListener(e -> {
            JDialog dialog = new JDialog(frame,"无标题",true);
            dialog.setVisible(true);
            dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
            dialog.setSize(200,100);
            dialog.setLocation(300,200);
        });
        menuItem2.addActionListener(e -> {
            menuItem2.addActionListener(e1 -> System.exit(0));
        });

        frame.setJMenuBar(menuBar);
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(myNotePad::Pad);
    }
}